package app.netant.book.xs37;

import java.io.File;
import java.net.URLEncoder;

import app.client.file.downs.FileDown;
/**
 * 久久 - 302 + 乱码处理
 * @author JiaJ
 *
 */
public class Xs37Down extends Thread {
	
	private String isDown = "0";
	
	private String filePath;
	private String url;
	
	private FileDown down;
	
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String isDown() {
		return isDown;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}

	public void setDown(String isDown) {
		this.isDown = isDown;
	}

	@Override
	public void run() {
		
		try {
			
			File file = new File(this.filePath);
			if(file.exists()){
				file.delete();
			}
			
			while(true){
				this.downFile(filePath, url);
				this.isDown = "1";
				break;
			}
			
		} catch (Exception e) {
			
			this.isDown = "2";
			
			File file = new File(this.filePath);
			if(file.exists()){
				file.delete();
			}
			
			e.printStackTrace();
			
		}
		
	}
	
	public void downFile(String filePath,String url) throws Exception{		
		this.down = new FileDown();
		down.downImage(url, filePath);		
	}
	
	/**
	 * 强制关闭
	 */
	public void stopThread(){
		if(this.down != null){
			this.down.stop();
		}
	}
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("开始测试下载");
		Xs37Down downControl = new Xs37Down();
		
		//http://m.jjxsw.com/e/DownSys/doaction.php?enews=DownSoft&classid=11&id=29407&pathid=0&pass=ee247a67a5adcf1dfb1abecbd1ff5635&p=:::
		//                  /e/DownSys/doaction.php?enews=DownSoft&classid=11&id=29407&pathid=0&pass=ee247a67a5adcf1dfb1abecbd1ff5635&p=:::
		downControl.downFile("D:/测试.txt", "https://u.37xs.com/packdown.php?id=47942&type=txt&fname=望门农家女");
		System.out.println("结束测试下载");
	}
	
}
